var util = (function () {
  let util = {};
  let _interfaceStr = ""
  util.paramMd5 = function (data) {
    var keyArr = [],
      valArr = [];
    for (var key in data) {
      if (data.hasOwnProperty(key)) {
        keyArr.push(key);
      }
    }
    keyArr.sort();
    for (var i = 0, len = keyArr.length; i < len; i++) {
      valArr.push(data[keyArr[i]]);
    }
    var sign = md5(valArr.join('|'));
    data.sign = sign;
    return data;
  };
  var gettype = Object.prototype.toString;
  util.getJSONData = function (data) {
    if (gettype.call(data) == '[object String]') {
      return JSON.parse(data);
    } else {
      return data;
    }
  };
  util.cookie = (function (doc, win) {
    return {
      getItem: function (key) {
        var cookieKey = key + '=';
        var result = '';
        if (doc.cookie.length > 0) {
          var index = doc.cookie.indexOf(cookieKey);
          if (index != -1) {
            index += cookieKey.length;
            var lastIndex = doc.cookie.indexOf(';', index);
            if (lastIndex == -1) {
              lastIndex = doc.cookie.length;
            }
            result = win.decodeURIComponent(doc.cookie.substring(index, lastIndex));
          }
        }
        return result;
      },
      setItem: function (name, value, domain, expires) {
        domain = domain || document.domain;
        if (typeof (expires) == 'undefiend' || expires == null || expires == '') {
          // 默认30天过期时间   
          var expTimes = 30 * 24 * 60 * 60 * 1000;
          var expDate = new Date();
          expDate.setTime(expDate.getTime() + expTimes);
          document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + expDate.toGMTString() + "; path=" + "/" + "; domain=" + domain;
        } else {
          var expTimes = expires * 1000;
          var expDate = new Date();
          expDate.setTime(expDate.getTime() + expTimes);
          document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + expDate.toGMTString() + "; path=" + "/" + "; domain=" + domain;
        }
      },
      removeItem: function (key) {
        // alert(key);
        var time = new Date();
        time.setDate(time.getDate() - 1);
        doc.cookie = key + '=0; expires=' + time.toGMTString();
        var cval = util.cookie.getItem(key);
        if (cval) {
          util.cookie.setItem(key, "0", '.lotto.sina.cn');
        }
      }
    };
  })(document, window);
  util.isIE = function (ver) {
    var b = document.createElement('b')
    b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->'
    return b.getElementsByTagName('i').length === 1
  }
  return util;
})();